package com.example.javadynamiccompile;

import javax.tools.SimpleJavaFileObject;
import java.net.URI;

/**
 * @author 陳樂
 * @version 1.0.0
 * @ClassName JavaSourceFromString.java
 * @Description TODO
 * @createTime 2023年03月30日 21:56:00
 */
public class JavaSourceFromString extends SimpleJavaFileObject {

    private final String code;

    public JavaSourceFromString(String name, String code) {
        super(URI.create("string:///" + name.replace('.', '/') + Kind.SOURCE.extension), Kind.SOURCE);
        this.code = code;
    }

    @Override
    public CharSequence getCharContent(boolean ignoreEncodingErrors) {
        return code;
    }
}
